﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Reflection;

namespace Baubixinh_client
{
    public partial class frmAddSeller : DevExpress.XtraEditors.XtraForm
    {
        public bool STAFFADDED { get; set; }

        public frmAddSeller()
        {
            InitializeComponent();
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmAddSeller_Load(object sender, EventArgs e)
        {
            try
            {
                DataTable objStore;

                objStore = clsDbAccess.fncGetAttributeValue(Program.gobjDb, clsEnum.ATTRIBUTE.STORE);
                txtStore.Properties.DataSource = objStore;

                txtStore.Focus();
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            try
            {
                if (!objValidation.Validate()) return;

                if(!clsCommon.fncMsgConfirm("Bạn có chắc muốn thêm nhân viên mới?")) return;

                Program.gobjTrans = Program.gobjConn.BeginTransaction();

                if(clsDbAccess.fncInsertStaff(Program.gobjDb, Program.gobjTrans, txtName.Text.Trim(), clsCommon.fncCnvNullToInt(txtStore.EditValue)))
                {
                    Program.gobjTrans.Commit();
                    this.STAFFADDED = true;
                    this.Close();
                }
                else
                {
                    Program.gobjTrans.Rollback();
                    this.STAFFADDED = false;
                    clsCommon.fncMsgError("Thêm nhân viên thất bại. Hãy kiểm tra lại dữ liệu.");
                }
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

    }
}